<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>修改医生信息</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layui/layuiAdmin/css/admin.css" media="all">
  <style>
    .st{
      width: 270px!important;
    }
    .layui-form-label{
      width: 120px!important;
    }
    .xinghao{
      color: red!important;
    }
  </style>
</head>
<body>

<!--表单-->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">上级部门</label>
    <div class="layui-input-inline">
      <select name="upDepet" id="upDepet" lay-filter="">
      </select>
    </div>
  </div>
  <!--  真实姓名  -->
  <div class="layui-form-item">
    <label class="layui-form-label">部门名称<span class="xinghao">*</span></label>
    <div class="layui-input-inline st">
      <input type="text" name="deptName" lay-verify="required|deptName" placeholder="请输入部门名称" autocomplete="off" class="layui-input">
    </div>
  </div>
  <!--  手机号码  -->
  <div class="layui-form-item">
    <label class="layui-form-label">所属医院<span class="xinghao">*</span></label>
    <div class="layui-input-inline">
      <select name="hospitalId" id="hospitalSelect" lay-filter="">
      </select>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">备注<span class="xinghao">*</span></label>
    <div class="layui-input-inline st">
      <input type="text" name="remark" lay-verify="required" placeholder="请输入备注" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">状态</label>
    <div class="layui-input-inline">
      <select name="status" lay-verify="required" lay-search>
        <option value="">请选择科室部门状态</option>
        <option value="1">正常</option>
        <option value="2">冻结</option>
      </select>
    </div>
  </div>
  <!--  提交 -->
  <div class="layui-form-item layui-hide">
    <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
  </div>
</div>

<script src="../../../layui/layui.js"></script>
<script>
  layui.use('laydate', function(){
    var laydate = layui.laydate;
    laydate.render({
      elem: '#datetimePicker',
      type: 'datetime'
    });
  });
  layui.config({
    base: '../../../layui/layuiAdmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'layer', 'form','layedit','laydate'], function(){
    var $ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,layedit = layui.layedit;

    //常规用法
    laydate.render({
      elem: '#hiredate'
    });

    // 通过后端动态获取下拉数据
    $.ajax({
      url:"http://localhost:8888/dept/findSysDepotsList",
      type:"get",
      dataType:"json",
      success:function (res){
        // 后端获取部门数据
        var selectData = res.data;
        // 清空列表
        $("#upDepet").empty();
        // 默认的
        $("#upDepet").append(new Option('-请选择上级部门-',''));
        // 循环遍历
        $.each(selectData,function (index,item){
          $("#upDepet").append(new Option(item.upName,item.upId));
        })
        form.render('select'); // 更新渲染
      }
    })
    var storedUsername = localStorage.getItem('hospitalId');
    console.log(storedUsername)
    // 通过后端动态获取下拉数据
    $.ajax({
      url:"http://localhost:8888/sys_hospital/findSysHospitalsById",
      type:"get",
      dataType:"json",
      data:{
        hospitalId:storedUsername
      },
      success:function (res){
        // 后端获取部门数据
        var selectData = res.data;
        // 清空列表
        $("#hospitalSelect").empty();
        // 默认的
        $("#hospitalSelect").append(new Option('-请选择所属医院-',''));
        // 循环遍历
        $.each(selectData,function (index,item){
          $("#hospitalSelect").append(new Option(item.hospitalName,item.hospitalId));
        })
        form.render('select'); // 更新渲染
      }
    })
    //创建一个编辑器
    var editIndex = layedit.build('LAY_demo_editor');
    //自定义验证规则
    form.verify({
      // contactsPhone: function(value){
      //     var reg = /^1[3-9]\\d{9}$|/;
      //     if(!reg.test(value)){
      //         return '以1开头的11位数字手机号';
      //     }
      // },
      deptName: function(value){
          if (value.length===0||value===''){
              return '部门名称不能为空';
          }
      },


    });

  })
</script>
</body>
</html>